#!/usr/bin/env python

import sqlalchemy as sa
import sqlalchemy.orm as sao

from model import DeclarativeBase

__all__ = ['ImageTag']


class ImageTag(DeclarativeBase):
    """
    The tags of image.

    Attributes:
        image_id: An integer for image primary key.
        tag_id: An integer for tag primary key.
    """

    __tablename__ = 'images_tags'

    id = sa.Column(sa.Integer, primary_key=True)
    """
    The primary key.

    @type: int
    """

    image_id = sa.Column(sa.Integer, sa.ForeignKey("images.id"),
                         nullable=False, index=True)
    """
    Image primary key.

    @type: int
    """

    tag_id = sa.Column(sa.Integer, sa.ForeignKey("tags.id"),
                       nullable=False, index=True)
    """
    Tag primary key.

    @type: int
    """

    image = sao.relationship('Image', uselist=False,
                             backref=sao.backref('image_tags'))
    """
    The Image instance of image_id.

    @type: model.Image
    """

    tag = sao.relationship('Tag', uselist=False,
                           backref=sao.backref('image_tags'))
    """
    The Tag instance of tag_id.

    @type: model.Tag
    """
